﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;

namespace Weazel.Willows.PreliminaryModel
{
	public class SignalFlowGraph 
		: Weazel.Willows.Model.SignalFlowGraph
	{		
		public SignalFlowGraph(Model model, Module parent, XmlElement xmlElement)	
			: base()
		{
			read(xmlElement);
		}

		#region Read from XML
		private void read(XmlElement description)
		{
			System.Diagnostics.Trace.Assert(description.HasAttribute("name"));

			// get the name
			this.LocalName = description.Attributes["name"].Value;
						
			// read the expression(s)
			// read expressions
			foreach (XmlNode node in description.GetElementsByTagName("Expression"))
			{
				System.Diagnostics.Debug.Assert(node is XmlElement);
				Expressions.Add(ExpressionReader.Read(node as XmlElement));
			}
		}
		#endregion

		public void ExpandTo(Weazel.Willows.Model.Module module)
		{
			System.Diagnostics.Trace.Assert(module != null);

			this.Parent = module;
			module.SignalFlowGraphs.Add(LocalName, this);
		}
	}
}
